﻿using System.Collections.Generic;

namespace WindowsPhoneMvp.Navigation
{
    /// <summary>
    /// Data that will be passed to the destination view upon navigation
    /// </summary>
    public class NavigationData
    {
        ///<summary>
        /// Parameters used passed in a navigation event
        ///</summary>
        public IDictionary<string, string> Parameters { get; private set; }
        /// <summary>
        /// The destination view name
        /// </summary>
        public string View { get; private set; }

        /// <summary>
        /// Create new NavigationData for the specified view
        /// </summary>
        /// <param name="view">The destination view</param>
        public NavigationData(string view)
        {
            View = view;
            Parameters = new Dictionary<string, string>();
        }

        /// <summary>
        /// Statically create new NavigationData to Navigate to the defined view
        /// </summary>
        /// <param name="view">The destination view</param>
        /// <returns>NavigationData with the specified view</returns>
        public static NavigationData For(string view)
        {
            var navData = new NavigationData(view);
            return navData;
        }

        /// <summary>
        /// Creates new NavigationData from the specified view and key value data
        /// </summary>
        public static NavigationData From(string view, string key, string value)
        {
            var navData = new NavigationData(view);
            navData.Parameters.Add(key, value);
            return navData;
        }

        /// <summary>
        /// Navigate with the specified key value data as a parameter
        /// </summary>
        public NavigationData With(string key, string value)
        {
            Parameters.Add(key, value);
            return this;
        }

        /// <summary>
        /// Navigate with the specified key value data as a parameter
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public NavigationData With(KeyValuePair<string,string> keyValue)
        {
            Parameters.Add(keyValue.Key, keyValue.Value);
            return this;
        }
    }
}
